package com.qsd.TeacherSystem.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import com.qsd.TeacherSystem.dao.CourseDao;
import com.qsd.common.po.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.qsd.TeacherSystem.Service.PaperService;
import com.qsd.common.enums.ResultStatus;
import com.qsd.common.vo.BaseVo;
import com.qsd.common.vo.PageVo;

import java.util.List;


/**
 * 
 * create by it_mck·Miao
 * 
 */
@Slf4j
@RestController
@RequestMapping("paper")
public class PaperController {
	
	@Resource
	private PaperService paperService;
	@Resource
	private CourseDao courseDao;
	
	/**
     * 搜索课程的所有试卷
     *
     * @param id 课程ID
     */
	@GetMapping("all")
	public PageVo<Paper> all(Integer id){
		if(id != null) {
			return paperService.all(id);
		}
		return new PageVo<>(ResultStatus.REQUEST_PARAM_MISS);
	}

	/**
     * 新增试卷
     *
     * @param paper
     * @param request
     * @return
     */
	@PostMapping("add")
	public BaseVo add(Paper paper, HttpServletRequest request) {
		log.info("新增试卷信息:{}",paper);
		Teacher teacher = (Teacher) request.getSession().getAttribute("teacher");
		return new BaseVo(paperService.add(paper, teacher.getUsername()));
	}

	/**
	 * 新增题库
     * @param paper
     * @param request
     * @return
     */
	@PostMapping("add2")
	public BaseVo add2(Paper paper, HttpServletRequest request) {
		log.info("新增试卷信息:{}",paper);
		Teacher teacher = (Teacher) request.getSession().getAttribute("teacher");
		ResultStatus resultStatus = paperService.add(paper, teacher.getUsername());
		return new BaseVo(resultStatus);
	}
	
	@PostMapping("update")
	public BaseVo update(Paper paper) {
		return new BaseVo(paperService.update(paper));
	}


	/**
	 *	删除题目
	 * @param type :题目类型:选择还是多选等
	 * @param id
	 * @return
	 */
	@PostMapping("delete")
	public BaseVo delete(String type, Integer id) {
		log.info("删除:type{},id",type,id);
		ResultStatus resultStatus = paperService.delete(type, id);
		return new BaseVo(resultStatus);
	}

	@PostMapping("addOneChoice")
	public BaseVo addOneChoice(OneChoice oneChoice) {
		return new BaseVo(paperService.addOneChoice(oneChoice));
	}
	
	@PostMapping("addMultipleChoice")
	public BaseVo addMultipleChoice(MultipleChoice multipleChoice) {
		return new BaseVo(paperService.addMultipleChoice(multipleChoice));
	}
	
	@PostMapping("addJudgment")
	public BaseVo addJudgment(Judgment judgment) {
		return new BaseVo(paperService.addJudgment(judgment));
	}
	
	@PostMapping("addFullInTheBlank")
	public BaseVo addFullInTheBlank(FullInTheBlank fullInTheBlank) {
		return new BaseVo(paperService.addFullInTheBlank(fullInTheBlank));
	}
	
	@PostMapping("addDiscussion")
	public BaseVo addDiscussion(Discussion discussion) {
		return new BaseVo(paperService.addDiscussion(discussion));
	}

}
